﻿using System;
using System.Drawing;
using System.IO;

namespace DevExpress.CrmDemo.Win.Helpers
{
    public static class FileHelpers
    {
        public static Bitmap GetFileIcon(string filepath)
        {
            if (string.IsNullOrEmpty(filepath) || !File.Exists(filepath))
                return null;

            Icon foundIcon = null;

            try
            {
                foundIcon = Icon.ExtractAssociatedIcon(filepath);
            }
            catch
            {
            }

            if (foundIcon != null)
            {
                return foundIcon.ToBitmap();
            }
            else
            {
                return null;
            }
        }
    }
}
